cask 'soapui' do
  version '5.3.0'
  sha256 '3d82a64d0573f136511b3591c060d59d78e8db356fc03df4d003dce83ec967c8'

  # cdn01.downloads.smartbear.com/soapui was verified as official when first introduced to the cask
  url "http://cdn01.downloads.smartbear.com/soapui/#{version}/SoapUI-#{version}.dmg"
  name 'SmartBear SoapUI'
  homepage 'https://www.soapui.org/'

  # Installer runs install4j from the distribution in quiet mode.
  #
  # Because the defaults in the installation also launch the HermesJMS
  # installer, we also have to provide overrides for those defaults.
  #
  # The defaults below chose the options to:
  #   accept the license agreement
  #   install only SoapUI (not HermesJMS, the # tutorials, or source)
  #   install to /Applications
  #   don't create a desktop icon
  #   don't view the release notes
  #   don't launch SoapUI after installing.
  #
  # For future Cask maintainers, if any of these variables change in future
  # versions from SmartBear, you can run the installer manually and then
  # check the values in the following file generated by the installation:
  #   /Applications/SoapUI-${version}.app/Contents/java/app/.install4j/response.varfile
  #
  # And refer to the install4j command line options for additional information
  #   https://resources.ej-technologies.com/install4j/help/doc/index.html
  #
  installer script: {
                      executable: "SoapUI #{version} Installer.app/Contents/MacOS/JavaApplicationStub",
                      args:       [
                                    '-q',
                                    '-Vsys.adminRights$Boolean=true',
                                    '-Vsys.programGroupDisabled$Boolean=true',
                                    '-VcreateDesktopLinkAction$Boolean=false',
                                    '-Vsys.component.2393$Boolean=false',
                                    '-Vsys.component.132$Boolean=true',
                                    '-Vsys.component.1263$Boolean=false',
                                    '-Vsys.languageId=en',
                                    '-VshowFileAction$Boolean=false',
                                    '-Vsys.installationDir=/Applications',
                                    '-VexecutionLauncherAction$Boolean=false',
                                    '-Vsys.component.714$Boolean=true',
                                  ],
                    }

  postflight do
    soapui_sh = "/Applications/SoapUI-#{version}.app/Contents/java/app/bin/soapui.sh"
    IO.write(soapui_sh, IO.read(soapui_sh).gsub('#   JAVA_OPTS="$JAVA_OPTS -Dsoapui.browser.disabled=true"', '   JAVA_OPTS="$JAVA_OPTS -Dsoapui.browser.disabled=true"'))

    vmoptions_txt = "/Applications/SoapUI-#{version}.app/Contents/vmoptions.txt"
    IO.write(vmoptions_txt, '-Dsoapui.browser.disabled=true')
  end

  uninstall delete: "/Applications/SoapUI-#{version}.app"

  zap trash: [
               '~/.soapuios',
               '~/default-soapui-workspace.xml',
               '~/soapui-settings.xml',
             ]
end
